from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://weapp.eteams.cn/sp/ebdapp/home")
    page.goto("https://passport.eteams.cn/login?service=https%3A%2F%2Fweapp.eteams.cn%2Fsp%2Febdapp%2Fhome")
    page.locator("input[type=\"text\"]").click()
    page.locator("input[type=\"text\"]").fill("132657597924908")
    page.locator("input[type=\"password\"]").click()
    page.locator("input[type=\"password\"]").fill("a123456")
    page.get_by_role("button", name="登录").click()
    page.get_by_text("自动化测试UI22kk").first.click()
    page.get_by_text("后台管理").click()
    page.get_by_role("link", name="页面 (1)").click()
    with page.expect_popup() as page1_info:
        page.locator(".weapp-ebd-card > div > div").first.click()
    page1 = page1_info.value
    page1.get_by_role("button", name="×").click()
    page1.locator("div:nth-child(2) > .ui-collapse-panel > .ui-collapse-panel__content-box > .ui-collapse-panel__content > .weapp-ebde-category > span > span").first.click()
    page.get_by_role("link", name="报表").click()
    page.get_by_role("link", name="表单").click()
    page.get_by_role("button", name="+ 新建表单").click()
    page.locator("img").nth(2).click()
    page.get_by_placeholder("请输入").first.click()
    page.get_by_placeholder("请输入").first.fill("121")
    with page.expect_popup() as page2_info:
        page.get_by_role("button", name="保存").click()
    page2 = page2_info.value
    page2.get_by_role("button", name="保存").click()
    page2.close()
    page1.locator("#ebpage_818252649310986240 svg").nth(4).click()

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
